<template>
    <div>
        <Select v-model="model1" style="width:200px" @on-change="selectall">
            <Option v-for="item in data" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select>
        <Table border :columns="columns6" :data="data6" style="margin-top: 40px">
            <template slot-scope="{ row }" slot="action">
                <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">查看详情</Button>
            </template>
            <template slot-scope="{ row }" slot="percent">
                使用量比上个月增加了{{row.percent}}%
            </template>
        </Table>
        <Row type="flex" justify="end" style="margin-top: 25px">
            <Page :total="total" show-total  @on-change="page1"/>
        </Row>
    </div>
</template>

<script>
import { getSumMoneyList } from '@/api/user'
export default {
  data () {
    return {
      page: 1,
      total: 0,
      model1: 1.3,
      data: [
        {
          value: 1.2,
          label: '超出20%'
        },
        {
          value: 1.3,
          label: '超出30%'
        },
        {
          value: 1.4,
          label: '超出40%'
        },
        {
          value: 1.5,
          label: '超出50%'
        }
      ],
      lists: [],
      rate: 1.3,
      columns6: [
        {
          title: '序号',
          type: 'index',
          width: 80,
          align: 'center'
        },
        {
          title: '单位名称',
          key: 'company',
          align: 'center'
          // width: 500
        },
        {
          title: '问题类型',
          slot: 'percent',
          align: 'center'
        },
        {
          title: '预警日期',
          key: 'business_date',
          align: 'center'
          // width: 150
        }
      ],
      data6: [],
      data5: []
    }
  },
  methods: {
    page1 (page) {
      let pageSize = 10
      if (page === undefined) {
        this.data6 = this.data5.slice((this.page - 1) * pageSize, this.page * pageSize)
      } else {
        this.data6 = this.data5.slice((page - 1) * pageSize, page * pageSize)
      }
    },
    selectall (current) {
      console.log('1', current)
      // this.page = current
      getSumMoneyList().then(ret => {
        this.lists = ret.data.data
        let yeartmp = ''
        let tmpList = this.lists
        let targetList = []
        let temp_company = {}
        tmpList.forEach((item, index) => {
          item.new_money = item.money || 0
          item.count_money = item.new_money * this.model1
          let times = item.business_date.split('-')
          if (yeartmp === times[0] && times[1] !== '01' && temp_company[item.company] && item.new_money >= temp_company[item.company].count_money) {
            item.percent = (((item.new_money - temp_company[item.company].new_money) / temp_company[item.company].new_money) * 100).toFixed(2)
            targetList.push(item)
            console.log(item, '11')
          }
          temp_company[item.company] = item
          yeartmp = times[0]
          // this.data6 = targetList
        })
        this.total = targetList.length
        this.data5 = targetList
        this.page1()
      })
    }
  },
  mounted () {
    this.selectall()
  }
}

</script>

<style scoped>

</style>
